﻿using System.Web.Mvc;

namespace CTools.Controllers
{
    public class OperaLoggerAttribute : FilterAttribute, IActionFilter
    {
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {

        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string strParams = "";
            var actionParameters = filterContext.ActionDescriptor.GetParameters();
            foreach (var p in actionParameters)
            {
                if (p.ParameterType == typeof(string))
                {
                    if (filterContext.ActionParameters[p.ParameterName] != null)
                    {
                        strParams += "&" + p.ParameterName + "=" + filterContext.ActionParameters[p.ParameterName];
                    }
                }
            }
            Common.Msg.Log.GetLog.Info("请求记录", new { filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, filterContext.ActionDescriptor.ActionName, strParams });
        }
    }
}